// pages/store_lists/store_lists.js
const app = getApp();
var request = require("../../utils/request.js");
var limit = 10;
var page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    store_list: [
      {
        store_img: "https://image.hongyantu.com/hongyantu/2018/10/28/059407684315407328438967204.png",
        store_title: "二胎妈妈首选特惠产品亲子系列",
        store_xian_price: "899",
        store_yuan_price: "899",
        store_sold: "99"
      },
      {
        store_img: "https://image.hongyantu.com/hongyantu/2018/10/28/059407684315407328438967204.png",
        store_title: "二胎妈妈首选特惠产品亲子系列",
        store_xian_price: "899",
        store_yuan_price: "899",
        store_sold: "99"
      },
      {
        store_img: "https://image.hongyantu.com/hongyantu/2018/10/28/059407684315407328438967204.png",
        store_title: "二胎妈妈首选特惠产品亲子系列",
        store_xian_price: "899",
        store_yuan_price: "899",
        store_sold: "99"
      }      
    ],
    show_have: true    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //快捷导航跳转
    this.turn = request.turn;
    this.close_modal = request.close_modal;
    this.store_list(options.storeId);
    this.setData({
      storeId: options.storeId
    })
  },
  //产品
  store_list: function (storeId){
    var that = this;
    var data = {
      limit: limit,
      page: page,
      storeId: storeId
    }
    request.request(app.globalData.getProdeuctList, data, function (res) {
      console.log(res)
      if(res.code == 0){
        that.setData({
          store_list: res.productList,
          img_url: request.url  + "/",
        })

      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  tap_product_detail: function () {
    wx.navigateTo({
      url: '/pages/phone_detail/phone_detail',
    })
  },
  scroll_bottom:function(){
    page++;
    var that = this;
    var store_list = this.data.store_list;
    var data = {
      limit: limit,
      page: page,
      storeId: this.data.storeId
    }
    request.request(app.globalData.getProdeuctList, data, function (res) {
      console.log(res)
      if (res.code == 0) {
        for (var i in res.productList){
          store_list.push(res.productList)
        }
        that.setData({
          store_list: store_list,
        })

      }
    })    
  }  
})